package com.shujia.scala


import scala.collection.mutable
import scala.collection.mutable.HashSet

object Demo16Set {

  def main(args: Array[String]): Unit = {

    /**
      * set 无序唯一
      *
      */

    val set: Set[Int] = Set(12, 3, 123, 124, 123, 124, 12, 321, 4, 123, 123124, 32)

    println(set)

    println(set.max)
    println(set.min)
    println(set.sum)
    println(set.mkString(","))
    println(set.map(i => i * 2))
    println(set.filter(i => i % 2 == 1))


    val s1 = Set(1, 2, 3, 4, 5, 6, 7)
    val s2 = Set(3, 4, 5, 6, 7, 8, 9)

    println(s1 & s2) //交集
    println(s1 | s2) //并集
    println(s1 &~ s2) //差集


    /**
      * 可变Set
      *
      */

    val hashSet = new mutable.HashSet[String]()

    hashSet.add("java")

    hashSet += "spark"

    println(hashSet)

    //清空
    hashSet.clear()

    println(hashSet)


  }

}
